// (c) Copyright 2013-2014 Stephen Gold <sgold@sonic.net>
// Distributed under the terms of the GNU General Public License

/*
 This file is part of the Bats Game.

 The Bats Game is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by the
 Free Software Foundation, either version 3 of the License, or (at your
 option) any later version.

 The Bats Game is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.

 You should have received a copy of the GNU General Public License
 along with the Bats Game.  If not, see <http://www.gnu.org/licenses/>.
 */
package bats.scene;

/**
 * Enumerate the pre-set lighting conditions.
 *
 * @author Stephen Gold <sgold@sonic.net>
 */
public enum LightingPreset {
    // *************************************************************************
    // values

    DAWN, MORNING, AFTERNOON, DUSK, NIGHT, VOID;
    // *************************************************************************
    // constants
    /**
     * items in the "select lighting" popup menu
     */
    final public static String selectLightingItems[] = {
        "dawn", "morning", "afternoon", "dusk", "night", "void"
    };
    // *************************************************************************
    // new methods exposed

    /**
     * Look up the cloud density for this preset.
     *
     * @return relative density (&le;1, &ge;0)
     */
    float cloudiness() {
        switch (this) {
            case DAWN:
                return 0.5f;
            case MORNING:
                return 1f;
            case AFTERNOON:
                return 0f;
            case DUSK:
                return 0f;
            case NIGHT:
                return 0.2f;
            case VOID:
                return 0f;
        }
        throw new IllegalStateException();
    }

    /**
     * Look up the textual description of this preset.
     */
    public String describe() {
        switch (this) {
            case DAWN:
                return "dawn";
            case MORNING:
                return "morning";
            case AFTERNOON:
                return "afternoon";
            case DUSK:
                return "dusk";
            case NIGHT:
                return "night";
            case VOID:
                return "void";
        }
        return "?";
    }

    /**
     * Find a preset value based on its textual description.
     *
     * @param description
     * @return preset value, or null if not found
     */
    public static LightingPreset fromDescription(String description) {
        for (LightingPreset preset : LightingPreset.values()) {
            if (preset.describe().equals(description)) {
                return preset;
            }
        }
        return null;
    }

    /**
     * Get the time of day for this preset. (Not defined for VOID preset.)
     *
     * @return number of hours since midnight (&lt;24, &ge;0)
     */
    float hour() {
        switch (this) {
            case DAWN:
                return 6.5f;
            case MORNING:
                return 10f;
            case AFTERNOON:
                return 14f;
            case DUSK:
                return 17.5f;
            case NIGHT:
                return 22f;
        }
        throw new IllegalStateException();
    }

    /**
     * Get the successor to this preset.
     *
     * @return the next preset value (not null)
     */
    public LightingPreset next() {
        switch (this) {
            case MORNING:
                return AFTERNOON;
            case AFTERNOON:
                return DUSK;
            case DUSK:
                return NIGHT;
            case NIGHT:
                return DAWN;
            case DAWN:
                return VOID;
            default:
                return MORNING;
        }
    }
}